#!/bin/bash

CONTAINER_NAME=doom-build-env
docker ps | grep $CONTAINER_NAME

if [ $? -eq 0 ]
then
echo "[INFO] doom builder found"

else
echo "[INFO] creating doom builder..."
docker run --rm -itd \
--name $CONTAINER_NAME \
-v $PWD:/doom \
doom-builder bash -x -c "\
useradd -u $(id -u) $USER && \
sleep 9999d
"

fi

echo "[INFO] start build..."
docker exec -it -u $(id -u) $CONTAINER_NAME bash -c "cd /doom/linuxdoom-1.10 && mkdir -p linux && make clean && make && ls -al linux"

